package com.geek.factory.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geek.factory.entity.Product;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-06-27
 */
public interface ProductMapper extends BaseMapper<Product> {
    @Update("UPDATE product SET complete_time = #{completeTime}, status = '1' WHERE id = #{productId}")
    void updateCompleteTime(@Param("productId") Long productId, @Param("completeTime") String completeTime);


    // 查询指定产品
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product selectById(@Param("id") Long id);

    // 插入新产品（复制）
    @Insert("INSERT INTO product(name, code, model, category, price, description, complete_time, status) " +
            "VALUES (#{name}, #{code}, #{model}, #{category}, #{price}, #{description}, #{completeTime}, #{status})")
    void insertNewProduct(Product product);


    @Select("SELECT * FROM product WHERE code = #{code}")
    Product selectByCode(@Param("code") String code);
}
